/*
 * Screen.h
 *
 *  Created on: 2020年11月13日
 *      Author: san
 */

#ifndef SCREEN_H_
#define SCREEN_H_

#include <string>
#include <vector>
#include "Sales_data.h"
#include "Screen.h"
#include "Winsowmgr.h"

using std::vector;

class Screen
{
public:
	typedef std::string::size_type pos;
	friend class Winsow_mgr;
//	friend void Winsow_mgr::clear(Winsow_mgr::ScreenIndex);

	Screen();
	Screen(pos ht, pos wd, char c): height(ht), width(wd),
			contents(ht * wd, c){};
	virtual ~Screen();  // 为什么eclipse默认的析构函数要写作虚函数呢, 答：为了动态绑定机制

	// 定义在类内部的成员函数都是自动inline的
	char get() const { return contents[cursor]; };  // 隐式内联
	char get(pos ht, pos wd) const;  // 显示内联

	// Action函数指针
	using Action = Screen &(Screen::*)();

	//光标移动函数
	Screen &home(){ height = 0; width = 0;}
	Screen &forward() {}
	Screen &back() {}
	Screen &up() {}
	Screen &down() {}

//	Screen &move(Directions);
	Screen &move(pos r, pos c);  // 能在之后呗设置为inline
	Screen &set(char c);
	pos size() const;

public:
	enum Directions { HOME, FORWARD, BACK, UP, DOWN };

private:
	pos cursor = 0;
	pos height = 0, width = 0;
	std::string contents;
	static Action Menu[];
};

//Screen &Screen::move(Screen::Directions cm)
//{
//	return (this->*Menu[cm])();
//}

inline Screen &Screen::move(pos r, pos c)
{
	pos row = r * width;
	cursor = row + c;
	return *this;
}

inline Screen &Screen::set(char c)
{
	contents[cursor] = c;  // 设置当前光标所在位置的新值
	return *this;
}

#endif /* SCREEN_H_ */
